package solutions.leetcode.easy;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/reverse-vowels-of-a-string/">345. 反转字符串中的元音字母</a>
 */
public class Solution345 {

    public String reverseVowels(String s) {
        char[] oc = s.toCharArray();
        int l = 0, r = s.length() - 1;
        while (l < r) {
            if (notVowel(oc[l])) {
                l++;
                continue;
            }
            if (notVowel(oc[r])) {
                r--;
                continue;
            }
            char t = oc[l];
            oc[l] = oc[r];
            oc[r] = t;
            l++;
            r--;
        }
        return String.valueOf(oc);
    }

    public boolean notVowel(Character c) {
        return c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u' &&
                c != 'A' && c != 'E' && c != 'I' && c != 'O' && c != 'U';
    }

    public static void main(String[] args) {
        Solution345 solution = new Solution345();
    }
}